#include<iostream>
#include<set>
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
class Solution {
public:
    ListNode *detectCycle(ListNode *head) {
		set<ListNode *> s;
		ListNode* cur;

		while(cur)
		{
			auto ret = s.insert(cur);
			if(ret.second == false)
				return cur;

			cur = cur -> next;
		}

		return nullptr;
    }
};

int main()
{

	return 0;
}
